package com.baiqian.doupo.command;

import com.baiqian.doupo.capability.DouPoModCapability;
import com.baiqian.doupo.capability.douqi.IDouQiCapability;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraftforge.common.util.LazyOptional;

public class AddLevelCommand implements Command<CommandSource> {
    public static AddLevelCommand instance = new AddLevelCommand();

    @Override
    public int run(CommandContext<CommandSource> context) {
        LazyOptional<IDouQiCapability> douQiCap = context.getSource().getEntity().getCapability(DouPoModCapability.DOUQI_CAPABILTTY);
        if(douQiCap.isPresent()){
            douQiCap.ifPresent((l) -> {
                l.setDouQiHaveMax(l.getDouQiHaveMaxLevelUp(), (PlayerEntity) context.getSource().getEntity());
                l.setDouQi(l.getDouQiHaveMax(),1,(PlayerEntity) context.getSource().getEntity());
            });
        }
        return 0;
    }
}
